import * as dayjs from 'dayjs'

export default function diff(date: number) {
	const time = Number(date)
	const now = new Date().getTime()
	const range = now - time
	if (range < 1000 * 60) {
		return dayjs(now).diff(dayjs(time), 'second') + '秒前'
	} if (range < 1000 * 60 * 60) {
		return dayjs(now).diff(dayjs(time), 'minute') + '分钟前'
	} if (range < 1000 * 60 * 60 * 24) {
		return dayjs(now).diff(dayjs(time), 'hour') + '小时前'
	} if (range < 1000 * 60 * 60 * 24 * 7) {
		return dayjs(now).diff(dayjs(time), 'day') + '天前'
	} else {
		return dayjs(time).format('YYYY-MM-DD HH:mm:ss')
	}
}
